#include "DeltaGlider.h"

//EnvironmentalLifeSupportSystem.cpp

void DeltaGlider::LifeSupportSystem()
{

 if (Update_Temp == 0) 
	{
		 
		Cabin_Temp_Timing = oapiGetSimTime() ;
        
	    Cabin_Temp_Timing = Cabin_Temp_Timing + 1;
	    Update_Temp = 1;
	    
		 

	}
	
	Cabin_Temp_Timing_check = oapiGetSimTime();

	if ((Update_Temp == 1) && (Cabin_Temp_Timing_check >= Cabin_Temp_Timing)) //>
	
		
	
	{
	
		double FPS = oapiGetFrameRate();
		Update_Temp = 0;
		if (is_behind == 0) 
		{
			
			CabinTemp += ((0.1 / FPS) * oapiGetTimeAcceleration ());
       		
	    }
	   if (is_behind == 1) 
		{

			CabinTemp += ((0.05 / FPS) * oapiGetTimeAcceleration ());
        }
	   
	   
      
	   if ((CabinThermostat == 1) && (battery_charge_001 > 5 ) && ( Radiator_loop == 1)) 
	   {
           RadiatorTemp1 += ((0.5 / FPS) * oapiGetTimeAcceleration ());
		   CabinTemp -= ((0.5 / FPS) * oapiGetTimeAcceleration ());
	   
		   if (CabinThermostat_battery_loop == 1) battery_draw_001 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 2) battery_draw_002 +=((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 3) battery_draw_003 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 4) battery_draw_004 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
	   }
       
	  if ((CabinThermostat == 1) && (can_power) && ( Radiator_loop == 2)) 
	   {
           RadiatorTemp2 += ((0.5 / FPS) * oapiGetTimeAcceleration ());
		   CabinTemp -= ((0.5 / FPS) * oapiGetTimeAcceleration ());
	   
		  if (CabinThermostat_battery_loop == 1)  battery_draw_001 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 2) battery_draw_002 +=((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 3) battery_draw_003 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 4) battery_draw_004 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
	   }

      if ((CabinThermostat == 1) && (can_power) && ( Radiator_loop == 3)) 
	   {
           RadiatorTemp3 += ((0.5 / FPS) * oapiGetTimeAcceleration ());
		   CabinTemp -= ((0.5 / FPS) * oapiGetTimeAcceleration ());
	   
		   if (CabinThermostat_battery_loop == 1) battery_draw_001 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 2) battery_draw_002 +=((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 3) battery_draw_003 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 4) battery_draw_004 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
	   }
	  if ((CabinThermostat == 1) && (can_power) && ( Radiator_loop == 4)) 
	   {
           RadiatorTemp4 += ((0.5 / FPS) * oapiGetTimeAcceleration ());
		   CabinTemp -= ((0.5 / FPS) * oapiGetTimeAcceleration ());
	   
		   if (CabinThermostat_battery_loop == 1) battery_draw_001 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 2) battery_draw_002 +=((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 3) battery_draw_003 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
		   if (CabinThermostat_battery_loop == 4) battery_draw_004 += ((0.001 / FPS) * oapiGetTimeAcceleration ());
	       
	  }
	



         
       

      if ((RadiatorThermostat1 == 1)&& (battery_charge_001 > 5 ))
	   {
           RadiatorTemp1 -= ((.5 / FPS) * oapiGetTimeAcceleration ());
		   	   
	      battery_draw_001 += ((.01 / FPS) * oapiGetTimeAcceleration ());
	  }

     if (RadiatorThermostat2 == 1)
	   {
           RadiatorTemp1 -= ((0.8 / FPS) * oapiGetTimeAcceleration ());
	  battery_draw_001 += ((0.1 / FPS) * oapiGetTimeAcceleration ());   	   
	   
	 }






	   if (CabinTemp > CabinThermostatSet + 2 ) CabinThermostat = 1;
	   if (CabinTemp < CabinThermostatSet - 2) CabinThermostat = 0;

       if (RadiatorTemp1 < 120) RadiatorThermostat1 = 0;
	   if (RadiatorTemp1 > 300) RadiatorThermostat1 = 1;

	   if (RadiatorTemp2 < 120) RadiatorThermostat2 = 0;
	   if (RadiatorTemp2 > 300) RadiatorThermostat2 = 1;
      
       if (RadiatorTemp3 < 120) RadiatorThermostat3 = 0;
	   if (RadiatorTemp3 > 300) RadiatorThermostat3 = 1;
       
	   if (RadiatorTemp4 < 120) RadiatorThermostat4 = 0;
	   if (RadiatorTemp4 > 300) RadiatorThermostat4 = 1;




	   // carbon_dioxide
	    
	   
	     if (carbon_dioxide_code == 1) 
		 {		 
			 carbon_dioxide_level_001 += (((0.00001* totalcrew) / FPS) * oapiGetTimeAcceleration ());
			battery_draw_001 += ((0.0001 / FPS) * oapiGetTimeAcceleration ());

		 }
		 if (carbon_dioxide_code == 2) 
		 {
			  carbon_dioxide_level_002 += (((0.00001* totalcrew) / FPS) * oapiGetTimeAcceleration ());
			battery_draw_001 += ((0.0001 / FPS) * oapiGetTimeAcceleration ());
		 }
		 
		 
		 if ((carbon_dioxide_code == 1) && (carbon_dioxide_level_001 > 1))  carbon_dioxide_code = 2;

        RadiatorTemp1 += ((0.0001 / FPS) * oapiGetTimeAcceleration ()); 
	    RadiatorTemp2 += ((0.0001 / FPS) * oapiGetTimeAcceleration ()); 
		RadiatorTemp3 += ((0.0001 / FPS) * oapiGetTimeAcceleration ());  
	    RadiatorTemp4 += ((0.0001 / FPS) * oapiGetTimeAcceleration ()); 
	
		if (battery_charge_001 > 100) battery_charge_001 = 100;
		if (battery_charge_001 < 100) battery_charge_001 += battery_charge_Rate_001;

   
}



}

   





